package com.xbongbong.sys.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;

import java.util.ArrayList;
import java.util.List;

public enum RoleEnum {

	/**
	 * 超级管理员
	 */
	ADMIN(1,"enum.role.name.admin","|1|", "admin", 0),

	/**
	 * 老板
	 */
	BOSS(2,"enum.role.name.boss","|2|", "boss", 10),

	/**
	 * 销售主管
	 */
	MANAGER(3,"enum.role.name.manager","|3|", "manager", 20),

	/**
	 * 销售
	 */
	SALE(4,"enum.role.name.sale","|4|", "sale", 30),

	/**
	 * 助理，表内的roleAlias是assist
	 */
	ASSISTANT(5,"enum.role.name.assistant","|5|", "assist", 40),

	/**
	 * 采购员
	 */
	PURCHASER(18,"enum.role.name.purchaser","|18|", "purchaser", 50),

	/**
	 * 仓管员
	 */
	WAREHOUSER(19,"enum.role.name.warehouser","|19|", "warehouser", 60),

	/**
	 * 财务
	 */
	TREASURER(20,"enum.role.name.treasurer","|20|", "treasurer", 70),

	/**
	 * 采购主管
	 */
	PURCHASE_MANAGER(21,"enum.role.name.purchase_manager","|21|", "purchase_manager", 80),

	/**
	 * 仓库主管
	 */
	WAREHOUSE_MANAGER(22,"enum.role.name.warehouse_manager","|22|", "warehouse_manager", 90),

	/**
	 * 工单主管
	 */
	WORKORDER_MANAGER(23,"enum.role.name.workorder_manager","|23|", "workOrder_manager", 100),

	/**
	 * 派单员
	 */
	WORKORDER_DISPATCHER(24,"enum.role.name.workorder_dispatcher","|24|", "workOrder_dispatcher", 110),

	/**
	 * 生产员
	 */
	PRODUCTION_WORKER(25,"enum.role.name.production_worker","|25|", "production_worker", 130),

	/**
	 * 生产主管
	 */
	PRODUCTION_MANAGER(26,"enum.role.name.production_manager","|26|", "production_manager", 140),

	/**
	 * 服务工程师
	 */
	SERVICE_ENGINEER(27,"enum.role.name.service_engineer","|27|", "service_engineer", 120),

	/**
	 * 短信设置编辑
	 */
	SMS_SET_UPDATE(383,"enum.role.name.sms_set_update","|383|", "sms_set_update", 150),
	;

	/** 枚举值 -- 角色id*/
	private final int		code;
	
	/** 枚举信息--角色中文名称 */
	private final String name;
	
	/**
	 * 枚举描述 --角色使用时状态
	 */
	private final String alias;

	/**
	 * tb_role表内 role_alias字段值
	 */
	private final String roleAlias;

	/**
	 * tb_role表没排序字段，就先放枚举里面吧
	 */
	private final Integer sort;

	/**
	 * 构造一个<code>SubModuleEnum</code>枚举对象
	 *
	 * @param code
	 * @param name
	 * @param alias
	 */
	private RoleEnum(int code, String name, String alias, String roleAlias, Integer sort) {
		this.code = code;
		this.name = name;
		this.alias = alias;
		this.roleAlias = roleAlias;
		this.sort = sort;
	}
	
	/**
	 * @return Returns the code.
	 */
	public int getCode() {
		return code;
	}
	
	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return I18nMessageUtil.getMessage(name);
	}
	
	/**
	 * @return Returns the alias.
	 */
	public String getAlias() {
		return alias;
	}
	/**
	 * @return Returns the roleAlias.
	 */
	public String getRoleAlias() {
		return roleAlias;
	}

	/**
	 * @return Returns the roleAlias.
	 */
	public Integer getSort() {
		return sort;
	}

	/**
	 * 通过枚举<code>alias</code>获得枚举
	 *
	 * @param alias
	 * @return WxErrorCodeEnum
	 */
	public static RoleEnum getByAlias(String alias) {
		for (RoleEnum cacheCode : values()) {
			if (cacheCode.getAlias().equals(alias)) {
				return cacheCode;
			}
		}
		return null;
	}
	
	/**
	 * 通过枚举<code>code</code>获得枚举
	 *
	 * @param code
	 * @return WxErrorCodeEnum
	 */
	public static RoleEnum getByCode(Integer code) {
		for (RoleEnum cacheCode : values()) {
			if (code.equals(cacheCode.getCode())) {
				return cacheCode;
			}
		}
		return null;
	}
	
	/**
	 * 获取全部枚举
	 * 
	 * @return List<WxErrorCodeEnum>
	 */
	public List<RoleEnum> getAllEnum() {
		List<RoleEnum> list = new ArrayList<RoleEnum>();
		for (RoleEnum cache : values()) {
			list.add(cache);
		}
		return list;
	}

	/**
	 * 获取全部枚举值
	 * 
	 * @return List<String>
	 */
	public List<String> getAllEnumAlis() {
		List<String> list = new ArrayList<String>();
		for (RoleEnum cache : values()) {
			list.add(cache.getAlias());
		}
		return list;
	}
	
}
